<?php

namespace framework\system\kernel;

/**
 * Description of exception
 *
 * @author xiaolei
 */
class ExceptionEx extends \Exception
{

    static public function errorHandler($errno = NULL, $errstr = NULL, $errfile = NULL, $errline = NULL)
    {
	/**
	 * 
	 */
	$levels = array(
	    E_ERROR => 'Error',
	    E_WARNING => 'Warning',
	    E_PARSE => 'Parsing Error',
	    E_NOTICE => 'Notice',
	    E_CORE_ERROR => 'Core Error',
	    E_CORE_WARNING => 'Core Warning',
	    E_COMPILE_ERROR => 'Compile Error',
	    E_COMPILE_WARNING => 'Compile Warning',
	    E_USER_ERROR => 'User Error',
	    E_USER_WARNING => 'User Warning',
	    E_USER_NOTICE => 'User Notice',
	    E_STRICT => 'Runtime Notice'
	);

	/*
	 * 如果这个错误类型没有包含在error_reporting里
	 * @会修改错误级别
	 */
	if (!(error_reporting() & $errno)) {

	    return TRUE;
	}

	/**
	 * 
	 */
	foreach ($levels as $key => $value) {

	    if ($key == $errno) {
		$errno = $value;
		break;
	    }
	}

	/**
	 * 
	 */
	$errorData = array(
	    'httpCode' => 500,
	    'errno' => $errno,
	    'errstr' => $errstr,
	    'errfile' => $errfile,
	    'errline' => $errline
	);
	var_dump($errorData);
    }

    static public function exceptionHandler(CException $e)
    {
	$errorData = array(
	    'httpCode' => 404,
	    'errno' => 'Exception',
	    'errstr' => $e->getMessage(),
	    'errfile' => $e->getFile(),
	    'errline' => $e->getLine()
	);

	/**
	 * 
	 */
	var_dump($errorData);
	var_dump($e);
	echo "<pre>".$e->xdebug_message."</pre>";
    }

}
